
 window.onload = function () {
  let flag = false;
        $("tel").onblur = function () {
            if ($("tel").value == "") {
                $("msg").innerHTML = "亲，用户名不能是空的昂！";
            }
            //2)、格式判断
            // 用户名有数字，字母组成，但不能以数字开头，2-10位
            let reg = /^[a-zA-Z]\w{1,9}$/;
            if (!reg.test($("tel").value)) {
                this.nextElementSibling.innerHTML = "亲，用户名格式不对哦";
            } else {
                ajax({
                    url: "../php/checkUser.php",
                    params: "username=" + this.value,
                    callback: function (result) {
                        if (result == "1") {
                            $("msg").innerHTML = "√ 亲，该用户名可以使用，赶紧注册吧！ ";
                            flag=true;
                        } else {
                            $("msg").innerHTML = "× 亲，该用户名已经存在 ";
                            flag=false;
                        }
                    }
                });
            }
        }

        $("pass").onblur = function () {

            let reg = /^[a-zA-Z_]\w{5,14}$/;
            if (reg.test(this.value)) {
                this.nextElementSibling.innerHTML = "√";
            } else {
                this.nextElementSibling.innerHTML = "&nbsp;&nbsp;&nbsp;只能是 数字字母下划线，且数字不能开头";
            }
        }



        $("signIn").onclick = function () {
            if ($("pass").vaule != "" || $("tel").value != "") {
                let str = `username=${$("tel").value}&userpass=${$("pass").value}`;
            if(flag==true){
                ajax({
                    url: "../php/addUser.php",
                    method:'POST',
                    params: str,
                    callback: function (data) {
                        console.log(data);
                        if (data == 'success') {
                            console.log(7);
                            location.href = "../html/register_page.html";
                            alert("注册成功，请您登陆！")
                        } else {
                            console.log(55);
                            alert("亲，注册失败！");
                        }
                    }
                });
            }else{
                alert("注册失败");
            }
                
            } 
//         else {
//                 console.log(5);
//                 alert("亲，不能乱点哦！")
//             }


        }
    }

 function $(id) {
    return document.getElementById(id);
 }

